<?php
//module game đã chơi của user
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class log_user_game_play_module extends CI_Module {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "log_user_game_play";
    public $primaryKey = "lugame_play_id";
    public $resCode = "LOG_USER_GAME_PLAY";

	public function init() {
		$this->load->model('muser');
	}
	
	public function active() {
		
	}
	
	public function deactive() {
		
	}
	
	public function admin($config) {
		$this->view('admin', $config);
	}
	
	public function run($config) {
		$game_id = @$this->msystem->get_global('game_id');
		if(isset($game_id ) && $game_id >0){
			$this->insert_log($game_id);
		}
	}
	
    function field() {
		$fieldData = array();
		$fieldData['use_id'] = 0;
		$fieldData['game_id'] = 0;
		$fieldData['session_id'] = '';
		$fieldData['lugame_play_ip'] = '';
		$fieldData['lugame_play_time_create'] = time();
		return $fieldData;
    }
	
	function insert_log($game_id = 0, $user_id = 0)
	{
		if($user_id  == 0){
			$user_id  = $this->muser->use_id;
		}
		if(!$user_id || $user_id<=0)
			return '';
		$this->insert(array(
			'use_id'=>$user_id, 
			'game_id'=>$game_id,
			'session_id'=>$this->session->userdata('session_id'),
			'lugame_play_ip'=>$this->input->ip_address(),
			'lugame_play_time_create' =>time()
			));
	}

	//Model 
	function get_game_by_user($user_id = 0) {
		if ($user_id > 0)
		return $this->db
				->from($this->mytable . ' as gp')
				->join('game as g', 'g.game_id = gp.game_id')
				->where ('gp.use_id = ', $user_id)
				//->order_by('ugame_play_id desc')
				->get()->result();
		return null;
	}
}

?>